<?php
/**
 * Ressource Document Popup
 *
 */
use Fox\Behaviors;
use Fox\Html\Header\Content;
use Fox\Generator;
use Fox\Html\Button;

$xview = Xview::instance();
$contact = $xview->component('ressource', 'object');
// Customizing
$customizing = Hive\Ressource\Customizing::instance();
$customizing->trackSummaryPage(array('mod' => 'ressource','act'=>'documents'));

$upload = $xview->val('upload');
$ajax = $xview->val('xvtrs');
$reload =$xview->val('reload');
/* @var $ressource Hive\Ressource */
$resumes = $contact->resumes();
$header = new Content('documents',Msg(Hive::BUNDLE,Hive::MENU_DOCUMENTS));
$header->add(new Button('add','?'))
	->color(Button::COLOR_WARNING)
	->behaviors(Behaviors::action(
	Generator::url('documents','upload',null,array('inlineid' => $contact->getId(),'index'=> true,'classname' => $contact::className())),
	true
));

if($upload)
{
	try {
		$ressource->uploadDocument();
		$resumes = $ressource->resumes();
		Fox\Message::Success(Msq(Hive::BUNDLE,Hive::DOCUMENT_CORRECTLY_UPLOADED));
	}catch (Exception $e){
		Fox\Message::Error($e->getMessage());
	}
	catch (Fox\Object\Exception\Save $e){
		Fox\Message::Error($e->getMessage());
	}
}
if($ajax)
{
	echo Xview::instance()->messages();
}

// Documents Block
$bkdoc = Xview::instance()->component('ressource', 'documents',array('id' => $contact->getId()));
$bkdoc->item('documents')->bootstrapGrid();
$bkdoc->item('documents')->setDatas($resumes);
$bkdoc->cssClass('jobUpdateBlock');

if($reload) {
	echo $bkdoc->item('documents')->render();
}
else {
	$html = Xview::instance()->messages();
	$html.= $bkdoc->item("documents")->display();
	return '<div>
	<div class="page-header clearfix">
		'.$header->render().'
	</div>
	<div class="contentArea">
		<div class="mbs">
			'.$html.'
		</div>
	</div>
	</div>';
}